//
//  LaunchViewController.m
//  LFCWarmSystem
//
//  Created by 李福才 on 16/6/1.
//  Copyright © 2016年 李福才. All rights reserved.
//

#import "LaunchViewController.h"
#import "ViewController.h"
#import "StartPSWViewController.h"
@interface LaunchViewController (){
    UITextView *textView;
    UIImageView *imgView;
}

@end

@implementation LaunchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
    [self verfyDateOut];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)setUI {
    imgView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [imgView setImage:[UIImage imageNamed:@"pic.png"]];
    [self.view addSubview:imgView];
}

- (void)verfyDateOut {
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"DBOperation" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
    NSString *lastDate=[data objectForKey:@"lastDate"];
    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd"];
    NSDate *dateOut = [dateFormat dateFromString:lastDate];
    NSDate *dateNow = [NSDate date];
    NSComparisonResult result = [dateNow compare:dateOut];
    switch (result) {
        case NSOrderedSame:
        case NSOrderedAscending:{
        }break;
        case NSOrderedDescending:{
//            过期
            textView = [[UITextView alloc] initWithFrame:CGRectMake(0, (264+50)*WIDTHSCALE, self.view.frame.size.width, 400*WIDTHSCALE)];
            textView.text = NSLocalizedString(@"VersionRemind", @"您所使用的软件版本为测试版，稳定性和可靠性将无法保障，请联系您的产品客服");
            textView.font = [UIFont systemFontOfSize:14*WIDTHSCALE];
            textView.textColor = [UIColor blackColor];
            textView.backgroundColor=[UIColor clearColor];
            [self.view addSubview:textView];
        }break;
        default:
            break;
    }
    dispatch_async(dispatch_get_main_queue(), ^(void){
        if (textView) {
            [NSThread sleepForTimeInterval:3.0];
        }
        if ([[[UIApplication sharedApplication] keyWindow].rootViewController isKindOfClass:[StartPSWViewController class]]) {
            
        }else{
            ViewController *viewController = [[ViewController alloc] init];
            UIViewController *rootViewController = [[UINavigationController alloc]initWithRootViewController:viewController];
            [[UIApplication sharedApplication] keyWindow].rootViewController = rootViewController;
        }
    });
}
@end
